package aop;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.aop.ThrowsAdvice;

import java.lang.reflect.Method;

/*
 * ThrowsAdvice用于在方法调用过程中抛出异常时发出的通知
 * 此接口内没有方法，因为方法是通过反射调用的
 * 该接口的实现类须实现以下形式的方法
 * void afterThrowing([Method, args, target], ThrowableSubclass);
 */
public class CustomThrowsAdvice implements ThrowsAdvice {
    private Log log = LogFactory.getLog(this.getClass());

    public void afterThrowing(Method method, Object[] args, Object target, Throwable throwable) {
        log.info("对象" + target.getClass().getName() + "在执行方法" + method.getName() + "时出现异常\n" +
                "异常为" + throwable + "\n" +
                "有关异常的详细信息，请查看控制台日志");
    }
}
